<?php 	
$matchdayId = Doctrine::getTable('BbMatchday')->getMatchdayId($seasonId);
$matchday = Doctrine::getTable('BbMatchday')->findOneById($matchdayId);
$matches = Doctrine::getTable('BbMatch')->getMatches(20, $matchdayId);
?>
<?php $season = Doctrine::getTable('BbSeason')->findOneBySId($seasonId)?>
<?php $league = Doctrine::getTable('BbLeague')->findOneById($season->getLId())?>
<li class="league">
    <?php echo image_tag("/uploads/league/".$league->getLogo(), array('alt'=>$league, 'style'=>'max-width:50px;max-height:50px;'))?>
</li>
<?php if($matchday) { ?>
<li class="red">
    <?php  echo $matchday.": ".$matchday->getMDescr(); ?>
</li>
<?php } ?> 
<?php 
$i=0;
$total = sizeof($matches);
foreach($matches as $match):
$team1 = $match->getBbTeams();
$team2 = $match->getBbTeams_2();   

if($match->published == 1 ) { 
if($match->m_played == 1) { 
?>
  <li class="green <?php if($i++==0) echo ' first'; if($i==($total-1)) echo ' last'?>" >
    <table width="100%;">
      <!--<tr><td colspan="2" align="center"><div style="background:#ccc;border-bottom:1px solid #aaa;height:8px;-moz-border-radius:5px 5px 0 0;">preview</div></td></tr>-->
      <tr><td colspan="2" align="center"><span class="time"><?php echo substr($match->getMDate() , 11, 5)?></span></td></tr>
      <tr>
        <td align="middle"><a href="<?php echo url_for('team/show?seasonId='.$seasonId.'&name='.$team1->getTName())?>"><span class="teamname"><?php echo $team1->getTAbrname()?></span></a></td>
        <td align="middle"><a href="<?php echo url_for('match/show?seasonId='.$seasonId.'&id='.$match->getId())?>"><span <?php if( $match->getScore1() > $match->getScore2()) echo "class=\"win\"" ?> ><?php echo $match->getScore1()?></span></a></td>
      </tr>
      <tr>
        <td align="middle"><a href="<?php echo url_for('team/show?seasonId='.$seasonId.'&name='.$team2->getTName())?>"><span class="teamname"><?php echo $team2->getTAbrname()?></span></a></td>
        <td align="middle"><a href="<?php echo url_for('match/show?seasonId='.$seasonId.'&id='.$match->getId())?>"><span <?php if( $match->getScore1() < $match->getScore2()) echo "class=\"win\"" ?> ><?php echo $match->getScore2()?></span></a></td>
      </tr>
    </table>
  </li>
<?php } else{ ?>
  <li <?php if($i++==0) echo ' first'; if($i==($total-1)) echo ' last'?>>
    <table width="100%;">
      <!--<tr><td colspan="2" align="center"><div style="background:#ccc;border-bottom:1px solid #aaa;height:8px;-moz-border-radius:5px 5px 0 0;">preview</div></td></tr>-->
      <tr><td colspan="2" align="center"><span class="time"><?php echo substr($match->getMDate() , 11, 5)?></span></td></tr>
      <tr>
        <td align="middle"><a href="<?php echo url_for('team/show?seasonId='.$seasonId.'&name='.$team1->getTName())?>"><span class="teamname"><?php echo $team1->getTAbrname()?></span></a></td>
        <td align="middle">-</td>
      </tr>
      <tr>
        <td align="middle"><a href="<?php echo url_for('team/show?seasonId='.$seasonId.'&name='.$team2->getTName())?>"><span class="teamname"><?php echo $team2->getTAbrname()?></span></a></td>
        <td align="middle">-</td>
      </tr>
    </table>
 </li>
<?php }} endforeach;?>